// packageC/pages/YearCardInvite/YearCardInviteDetail/YearCardInviteDetail.js
var common = require("../../../../public.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        isOverShare:true ,  //全局分享标识请勿删除
        inviteList: [], //邀请记录
        codeList: [],
        inviteListIng: [] //邀请中
    },
    goBack() {
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })
        } else {
            wx.redirectTo({
                url: '/pages/index/index',
            })
        }
    },
    //复制
    copyText(e) {
        wx.setClipboardData({
            data: e.currentTarget.dataset.text,
            success: function (res) {
                wx.getClipboardData({
                    success: (option) => {
                        wx.showToast({
                            title: '复制成功',
                        })
                    },
                })
            }
        })

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onChange(event) {
        // console.log(event.detail.index)
        let index = event.detail.index
        switch (index) {   //0 邀请中 1 邀请记录  2激活码奖励
            case 0:
                this.inviteListIng()
                break;
            case 1:
                this.inviteList()
                break;
            default:
                this.ji_huo()
        }
    },
    onLoad: function (options) {
        var that = this
        //获取胶囊位置
        console.log(options, "0087798987877")
        let capsule = wx.getMenuButtonBoundingClientRect()
        this.setData({
            height: capsule.height,
            top: capsule.top,
            cardId: options.annualCardId,
            inviteNum: options.inviteNum
        })
        var windowHeight = wx.getSystemInfoSync().windowHeight
        var windowWidth = wx.getSystemInfoSync().windowWidth
        this.setData({
            scroll_height: windowHeight * 750 / windowWidth - 200
        })
        common.getLocalUserInfo(function (success, data) {
            if (success) {
                that.setData({
                    userInfo: data.user,
                    token: data.token
                }, function () {
                    this.inviteList()
                    this.ji_huo()
                    this.inviteListIng()
                })
            } else {
                that.setData({
                    userInfo: null,
                    token: '',
                })
            }
        }, true)

    },
    inviteListIng() {
        let that = this
        common.get('/userAnnualCard/getShareNotCodeList', {
            cardId: that.data.cardId,
            userId: that.data.userInfo.id,
            token: that.data.token
        }, res => {
            if (res.status === 200) {
                console.log(res.data, "邀请中邀请中")
                that.setData({
                    inviteListIng: res.data
                })
            }
        })
    },
    inviteList() {
        let that = this
        common.get('/userAnnualCard/getSuccessShareRecord', {
            cardId: that.data.cardId,
            userId: that.data.userInfo.id,
            token: that.data.token
        }, res => {
            if (res.status === 200) {
                console.log(res.data, "3457122555555")
                that.setData({
                    inviteList: res.data
                })
            }
        })
    },
    ji_huo() {
        let that = this
        common.get('/userAnnualCard/getMyActivationCode', {
            cardId: that.data.cardId,
            userId: that.data.userInfo.id,
            token: that.data.token
        }, res => {
            if (res.status === 200) {
                that.setData({
                    codeList: res.data
                })
            }
        })
    },
    onShareAppMessage: function () {
        return {
            title: '分享有礼',
            path: '/pages/myNian/payCard/payCard?cardId=' + this.data.cardId + '&userId=' + this.data.userInfo.id,
            // imageUrl: '/images/home.png',
            success: (res) => {
                // 分享成功
            },
            fail: (res) => {
                // 分享失败
            }
        }
    },

})